<?php
namespace app\admin\controller;
use think\Db;
use think\Paginator;
use app\admin\model\Withdrawals as Withdrawal;
use app\admin\model\Cuser;

class Withdrawals extends Common
{
    protected $cModel;
    public function _initialize()
    {
        parent::_initialize();
        $this->cModel = new Withdrawal;
    }

    public function index()
    {
        $where = [];
        $order = ['id desc'];
        if(input('get.serach')){
            $where['user_id|account|bank'] =['like','%'.input('get.serach').'%'];
        }
        $dataList = $this->cModel->where($where)->order($order)->paginate('',false,page_param());
        $dataList = $this->cModel->selectList();

        // dump($dataList->toArray());die;
        $this->assign('dataList', $dataList);
        return $this->fetch();

    }

    public function edit($id)
    {
        if (request()->isPost()) {
            $data = input('post.');
            if($data['actions']=='tixian'){
                unset($data['actions']);
                $result = $this->cModel->where(['id'=>$data['id']])->update($data);
            }

            if ($result) {
                return ajaxReturn(lang('action_access'),url('index'));
            } else {
                return ajaxReturn($this->cModel->getError());
            }


        } else {

            if ($id > 0) {

                $data = $this->cModel->get($id);
                $telphone = Db::name('cuser')->field('id,telphone')->where(['id'=>$id])->find();
                $this->assign('telphone',$telphone);
                $this->assign('data', $data);
                return $this->fetch();
            }
        }

    }

    public function delete()
    {
        if(request()->isPost()){
            $id = input('id');
            $id_arr = explode(',',$id);
            $where = ['id'=>['in', $id_arr]];
            $result = $this->cModel->where($where)->delete();
            if ($result) {
                return ajaxReturn(lang('action_access'),url('index'));
            } else {
                return ajaxReturn($this->cModel->getError());
            }

        }
    }
}